package com.yang.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
/**
 * 描述：用户实体
 * 版本：1.0
 * 作者： 杨建全
 * 创建时间：2016年3月24日  上午10:22:45
 */
@Entity
@Table(name="t_user")
public class User {
	private String id;				//用户id	
	private String username;		//用户名
	private String password;		//用户密码
	private String nickname;		//用户昵称
	private String email;			//用户邮箱
	private int sex; 				//默认为0；0表示男，1表示女
	private Date createTime;		//创建时间
	private Set<Roles> roles;		//用户角色

	@Id
	@GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
	@Column(name = "uid", nullable = false, length = 9)
	public String getId() {
		return id;
	}
 
	public void setId(String id) {
		this.id = id;
	}
 
	@Column(name = "username", nullable = false, length = 20)
	public String getUsername() {
		return username;
	}
 
	public void setUsername(String username) {
		this.username = username;
	}
 
	@Column(name = "password", nullable = false, length = 32)
	public String getPassword() {
		return password;
	}
 
	public void setPassword(String password) {
		this.password = password;
	}
 
	@Column(name = "nickname", nullable = false, length = 16)
	public String getNickname() {
		return nickname;
	}

	@Column(name = "sex", nullable = false, length = 1)
	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	@Column(name = "email", nullable = false, length = 30)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@ManyToMany(fetch=FetchType.EAGER,cascade = {CascadeType.MERGE})
	@JoinTable(name = "t_user_role", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns = { @JoinColumn(name = "rid") })
	public Set<Roles> getRoles() {
		return roles;
	}
	public void setRoles(Set<Roles> roles) {
		this.roles = roles;
	}
	
	@Column(name="create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Override
	public String toString() {
		return "User [ \nid : " + this.id + "\nusername : " + this.username
				+ "\npassword : " + this.password + "\nsex : " + this.sex
				+ " ]";
	}
}
